import * as Cesium from 'cesium/Cesium'
import Measurement from "./Measurement";
import MeasurementSettings from "./MeasurementSettings";
import getWorldPosition from "./getWorldPosition";
import AngleUnits from "./AngleUnits";
import getSlope from "./getSlope";
import MeasureUnits from "./MeasureUnits";

var scratchCartesian$c = new Cesium.Cartesian3
    , scratchCartographic$g = new Cesium.Cartographic;
function getIcon(e) {
    return '<svg viewBox="0 0 30 30" height="' + e + 'px" width="' + e + 'px">\n                 <g transform="translate(0,-267)">\n                   <circle r="2.0788691" cy="281.90503" cx="15.212251"/>\n                 </g>\n               </svg>'
}
function PointMeasurement(e) {
    e = Cesium.defaultValue(e, Cesium.defaultValue.EMPTY_OBJECT),
        Measurement.call(this, e),
        this._point = this._pointCollection.add(MeasurementSettings.getPointOptions()),
        this._label = this._labelCollection.add(MeasurementSettings.getLabelOptions({
            horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
            verticalOrigin: Cesium.VerticalOrigin.CENTER,
            pixelOffset: new Cesium.Cartesian2(10, 0)
        })), this._position = new Cesium.Cartesian3, this._height = 0, this._slope = 0
}

PointMeasurement.prototype = Object.create(Measurement.prototype),
    PointMeasurement.prototype.constructor = PointMeasurement,
    Cesium.defineProperties(PointMeasurement.prototype, {
        position: {
            get: function () {
                return this._position
            }
        },
        height: {
            get: function () {
                return this._height
            }
        },
        slope: {
            get: function () {
                return this._slope
            }
        },
        type: {value: "点坐标"},
        icon: {
            value: getIcon(15)
        },
        thumbnail: {
            value: getIcon(25)
        },
        instructions: {value: ["移动鼠标查看点的经度、纬度和高度"]},
        id: {value: "pointMeasurement"}
    }), PointMeasurement.prototype._pickPositionSupported = function () {
    return this._scene.pickPositionSupported
}, PointMeasurement.prototype.handleMouseMove = function (e) {
    var t = this._scene;
    if (this.reset(), t.mode !== Cesium.SceneMode.MORPHING) {
        this._point.show = !1;
        var i = PointMeasurement._getWorldPosition(t, e, scratchCartesian$c);
        if (Cesium.defined(i)) {
            this._point.position = i;
            var r, n = t.frameState.mapProjection.ellipsoid.cartesianToCartographic(i, scratchCartographic$g),
                a = 0;
            Cesium.defined(t.globe) && (a = Cesium.defaultValue(t.globe.getHeight(n), 0)), a = n.height - a,
            Cesium.Math.equalsEpsilon(a, 0, Cesium.Math.EPSILON3) && (a = 0),
            t.mode !== Cesium.SceneMode.SCENE2D && (r = PointMeasurement._getSlope(t, e, this._primitives)), this._point.show = !0;
            var o = this._label;
            o.position = i, o.show = !0, o.text = "lon: " + MeasureUnits.angleToString(n.longitude, AngleUnits.DEGREES_MINUTES_SECONDS, this._selectedLocale)
                + "\nlat: " + MeasureUnits.angleToString(n.latitude, AngleUnits.DEGREES_MINUTES_SECONDS, this._selectedLocale),
            t.mode !== Cesium.SceneMode.SCENE2D && this._pickPositionSupported() && (o.text += "\n高度: "
                + MeasureUnits.distanceToString(a, this._selectedUnits.distanceUnits, this._selectedLocale),
            Cesium.defined(r) && (o.text += "\n倾斜度: " + MeasureUnits.angleToString(r, this._selectedUnits.slopeUnits, this._selectedLocale, 3))),
                this._position = Cesium.Cartesian3.clone(i, this._position), this._height = a, this._slope = r
        }
    }
}, PointMeasurement.prototype.reset = function () {
    this._label.show = !1, this._point.show = !1, this._position = Cesium.Cartesian3.clone(Cesium.Cartesian3.ZERO, this._position)
}, PointMeasurement.prototype.isDestroyed = function () {
    return !1
}, PointMeasurement.prototype.destroy = function () {
    return this._labelCollection.remove(this._label), this._pointCollection.remove(this._point), Cesium.destroyObject(this)
}, PointMeasurement._getSlope = getSlope, PointMeasurement._getWorldPosition = getWorldPosition;

export  default PointMeasurement;
